package gemini.castor.ui.client.page.content.store.shoppingcart;

import gemini.basic.model.Product;

import java.util.List;

import com.google.gwt.event.shared.GwtEvent;

public class ShoppingCartEvent extends GwtEvent<ShoppingCartHandler> {

	private static Type<ShoppingCartHandler> TYPE;
	
	public static Type<ShoppingCartHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<ShoppingCartHandler>();
		return TYPE;
	}
	
	public enum ForwardType {
		ADD, CHECK_OUT, UPDATE, REMOVE, VIEW_PRODUCT;
	}
	
	public ShoppingCartEvent(ForwardType forwardType) {
		super();
		this.setForwardType(forwardType);
	}
	
	private ForwardType forwardType;
	private List<ShoppingCartItem> items;
	private Product product;
	private String paymentType;
	private Long paymentValue;

	@Override
	protected void dispatch(ShoppingCartHandler handler) {
		if(forwardType.equals(ForwardType.ADD)){
			handler.onAdd(this);
		} else if(forwardType.equals(ForwardType.REMOVE)){
			handler.onRemove(this);
		} else if(forwardType.equals(ForwardType.UPDATE)){
			handler.onUpdate(this);
		} else if(forwardType.equals(ForwardType.CHECK_OUT)){
			handler.onCheckOut(this);
		} else if(forwardType.equals(ForwardType.VIEW_PRODUCT)){
			handler.onViewProduct(this);
		}
	}
	
	@Override
	public Type<ShoppingCartHandler> getAssociatedType() {
		return getType();
	}

	public void setForwardType(ForwardType forwardType) {
		this.forwardType = forwardType;
	}

	public ForwardType getForwardType() {
		return forwardType;
	}

	public void setItems(List<ShoppingCartItem> items) {
		this.items = items;
	}

	public List<ShoppingCartItem> getItems() {
		return items;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public Product getProduct() {
		return product;
	}

	public void setPaymentType(String paymentType) {
		this.paymentType = paymentType;
	}
	
	public String getPaymentType(){
		return paymentType;
	}

	public void setPaymentValue(Long paymentValue) {
		this.paymentValue = paymentValue;
	}

	public Long getPaymentValue() {
		return paymentValue;
	}
}
